package com.stlm2.controller;

import com.stlm2.dems.service.DdmGoodsService;
import com.stlm2.dems.service.DdmShopService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/ddmShopC")
public class DdmShopController {
    @Resource
    private DdmShopService ddmShopService;
    /*zlq
* crm查询店铺列表页面
* */
    @RequestMapping(value="/listView",produces="application/json;charset=UTF-8")
    public ModelAndView listView(ModelAndView modelAndView){
        modelAndView.setViewName("/ddmShop/list");
        return modelAndView;
    }
    /*zlq
* crm添加店铺页面
* */
    @RequestMapping(value="/addView",produces="application/json;charset=UTF-8")
    public ModelAndView addView(ModelAndView modelAndView){
        modelAndView.setViewName("/ddmShop/addShop");
        return modelAndView;
    }

    /*zlq
* crm店铺详情页面
* */
    @RequestMapping(value="/detailsView",produces="application/json;charset=UTF-8")
    public ModelAndView detailsView(ModelAndView modelAndView,String id){
        modelAndView.setViewName("/ddmShop/details");
        modelAndView.addObject("id",id);
        return modelAndView;
    }
    /*
    *zlq
    * 添加店铺
    * token:
    * name: 店铺名称
    * mainImg： 店铺主图
    * datailImg： 店铺详情图
    * location：店铺地址
    * contact： 店铺联系方式
    * linkman：店铺联系人
    * longitudeAndLatitude:经纬度
    * shopTypeValue:店铺类型 1：自营 2：他营
    * shopLevelValue：店铺等级
    *
     */
    @ResponseBody
    @RequestMapping(value="/add.json",produces="application/json;charset=UTF-8")
    public  String add(ModelMap model, String token,String name,String mainImg,String datailImg,String location,String contact,String linkman,String longitudeAndLatitude,String shopTypeValue,String shopLevelValue){
        String data=null;
        try {
            data=ddmShopService.add(model,token,name,mainImg,datailImg,location,contact,linkman,longitudeAndLatitude, shopTypeValue,shopLevelValue);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }

    /*
*CRM查询店铺列表
* zlq
* token:
* page:页码
* name:店铺名称
* location：店铺地址
* state：店铺状态 true：有效 false：无效 不传为所有
* shopTypeValue：店铺类型 1：自营 2：他营
* shopLevelValue：店铺等级
 */
    @ResponseBody
    @RequestMapping(value="/getList.json",produces="application/json;charset=UTF-8")
    public  String getList(ModelMap model, String token,String page,String name,String location,Boolean state,String shopTypeValue,String  shopLevelValue){
        String data=null;
        try {
            data=ddmShopService.getList(model,token,page, name,location,state,shopTypeValue,shopLevelValue);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
    /*
    *zlq
    * crm查询店铺详情
    * token:
    * id:店铺ID
     */
    @ResponseBody
    @RequestMapping(value="/crmDetails.json",produces="application/json;charset=UTF-8")
    public  String  crmDetails(ModelMap model,String token,String id){
        String data=null;
        try {
            data=ddmShopService.crmDetails(model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
*zlq
* crm查询所有有效的店铺的下拉框
* token:
* id:店铺ID
 */
    @ResponseBody
    @RequestMapping(value="/allshopSelect.json",produces="application/json;charset=UTF-8")
    public  String  allshopSelect(ModelMap model){
        String data=null;
        try {
            data=ddmShopService.allshopSelect(model);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
    /*
    *zlq
    * 修改店铺
    * token:
    * id：店铺Id
    * name: 店铺名称
    * mainImg： 店铺主图
    * datailImg： 店铺详情图
    * location：店铺地址
    * contact： 店铺联系方式
    * linkman：店铺联系人
    * longitudeAndLatitude:经纬度
    * shopTypeValue:店铺类型 1：自营 2：他营
    * shopLevelValue：店铺等级
    *
     */
    @ResponseBody
    @RequestMapping(value="/modification.json",produces="application/json;charset=UTF-8")
    public  String modification(ModelMap model, String token,String id,String name,String mainImg,String datailImg,String location,String contact,String linkman,String longitudeAndLatitude,String shopTypeValue,String shopLevelValue){
        String data=null;
        try {
            data=ddmShopService.modification(model,token,id,name,mainImg,datailImg,location,contact,linkman,longitudeAndLatitude, shopTypeValue,shopLevelValue);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }

    /*
    *启用店铺并铺货
    * zlq
    *
     */
    @ResponseBody
    @RequestMapping(value="/shopStart.json",produces="application/json;charset=UTF-8")
    public  String  shopStart(ModelMap model,String token,String id){
        String data=null;
        try {
            data=ddmShopService.shopStart(model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"启用店铺并铺货失败",data);
        }
        return  data;
    }

    /*
*无效店铺
* zlq
*
 */
    @ResponseBody
    @RequestMapping(value="/invalidShop.json",produces="application/json;charset=UTF-8")
    public  String  invalidShop(ModelMap model,String token,String id){
        String data=null;
        try {
            data=ddmShopService.invalidShop(model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"操作失败",data);
        }
        return  data;
    }
}
